package main

import (
	"bufio"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

func main() {

	// 文件名与真实卡牌名之间的映射
	nameMap := make(map[string]string)

	// 获取真实卡牌名
	nameFilePath := "G:\\OneDrive - 夏凯\\备份-实验室\\桌面\\新建文件夹\\新建文本文档 (2).txt"
	nameFile, err := os.Open(nameFilePath)
	if err != nil {
		fmt.Println("名字文件不存在")
	}
	reader := bufio.NewReader(nameFile)
	for {
		line, err := reader.ReadString('\n')
		if err != nil || io.EOF == err {
			break
		}
		index := strings.Index(line, "-")
		nameMap[line[0:index]] = line[index+1 : len(line)-1]
	}

	cardListPath := "F:\\IDM下载\\sif"
	cardList, _ := ioutil.ReadDir(cardListPath)
	for _, card := range cardList {
		oldName := card.Name()[0 : len(card.Name())-4]

		if strings.Index(oldName, "Round") >= 0 {
			_ = os.Remove(cardListPath + "\\" + card.Name())
			continue
		}
		newName := nameMap[oldName] + ".png"
		_ = os.Rename(cardListPath+"\\"+card.Name(), cardListPath+"\\"+newName)
		println(oldName + " 被重命名为 " + newName)
	}

}
